<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(0);
include_once dirname(dirname(dirname(__FILE__))) . '/mgtv_init.php';
define('ORG_ID', 'dltt');

class check_propram extends nn_timer
{

    public function action($params = null)
    {
        $this->msg('开始执行...');
        do_timer_action();
        $this->msg('执行结束...');
    }
}
$check_propram = new check_propram("check_propram", ORG_ID);
$check_propram->run();

function do_timer_action()
{
    set_time_limit(0);
    $db = nn_get_db(NL_DB_WRITE);
    $db -> open();
    $file = fopen("no_movie.csv", "r");
    while (!feof($file)) {
        $arr = (fgetcsv($file));
        $id = $arr[0];
        $sql = "select * from nns_mgtvbk_c2_task where nns_org_id='". ORG_ID ."' and nns_type='index' and nns_ref_id='$id'";
        $import_index = nl_db_get_one($sql,$db);
        if(empty($import_index)){
            continue;
        }
    
    
        echo PHP_EOL."====================================================================".PHP_EOL;
        echo $import_index['nns_name'];
    
        $sql_media = "select * from nns_mgtvbk_c2_task where nns_org_id='". ORG_ID ."' and nns_type='media' and nns_src_id='$id' and nns_action!='destroy'";
    
        $media_info = nl_db_get_one($sql_media,$db);
    
        if(empty($media_info)){
            echo "===========================No Meida Binging".PHP_EOL;
            error_log($import_index['nns_name'].",".$id.PHP_EOL,3,'no_media.log');
        }else{
            if($media_info['nns_status']==0){
                echo "===========================Have Media Binging".PHP_EOL;
                error_log($import_index['nns_name'].",".$id.",".$media_info['nns_ref_id'].PHP_EOL,3,'media.log');
            }else{
                echo "===========================Doing Binging".PHP_EOL;
                error_log($import_index['nns_name'].",".$id.",".$media_info['nns_ref_id'].PHP_EOL,3,'domedia.log');
            }
        }
    
    }
    fclose($file);
}

